const router = require('express').Router()
const U = {...require('../../utils'),...require('./utils')}
const Order = require('../../models/order')

function abort_no_id(req,res,next){
  if(req.body.id == null){
    res.json(U.Err('请提供菜品id'))
    return
  }
  next()
}

router.route('/')
  .all(U.abort_not_login)
  .get((req,res) => {
    res.json(U.Ok(Order.all()))
  })
  .post(abort_no_id,(req,res)=>{
    Order.add(req.session.user.id,req.body.id)
    res.json(U.Ok())
  })

module.exports = router